package observerPattern;



import observerPattern.observerAPattern.CustomerOne;
import observerPattern.observerAPattern.CustomerTwo;
import observerPattern.observerAPattern.ShopSubject;
import observerPattern.observerBPattern.Person;
import observerPattern.observerBPattern.TravelAgency;
import observerPattern.observerBPattern.WeatherStation;
import observerPattern.observerCPattern.WeChatOfficialAccount;
import observerPattern.observerCPattern.WeChatUser;
import org.junit.Test;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @program: course
 * @author: lsn
 * @create: 2024-04-28 10:41
 * @description: 客户端测试类
 */
public class ApiTest {

    @Test
    public void test(){
        // 创建具体主题
        WeChatOfficialAccount weChatOfficialAccount  = new WeChatOfficialAccount();
        // 创建微信用户
        WeChatUser user1 = new WeChatUser("孙悟空");
        WeChatUser user2 = new WeChatUser("猪悟能");
        WeChatUser user3 = new WeChatUser("沙悟净");
        //订阅公众号
        weChatOfficialAccount.attach(user1);
        weChatOfficialAccount.attach(user2);
        weChatOfficialAccount.attach(user3);
        //公众号更新发出消息给订阅的微信用户
        weChatOfficialAccount.notify("来了！新闻早班车");
    }

    @Test
    public void test1(){
        ShopSubject shop = new ShopSubject();
        CustomerOne boy = new CustomerOne(shop, "张大三");
        CustomerTwo girl = new CustomerTwo(shop, "李红花");
        shop.setDiscountGoods("数码相机",2345.9,2008.8);
        shop.setDiscountGoods("手机",1236,998);
    }

    @Test
    public void test2(){
        WeatherStation weatherStation = new WeatherStation();
        TravelAgency travelAgency = new TravelAgency();
        Person person = new Person(weatherStation,travelAgency);
        weatherStation.doForecast("10日","阴有小雨",28,20);
        travelAgency.giveMess("10日","黄山二日游");
        weatherStation.doForecast("11日","阴转多云",30,22);
        travelAgency.giveMess("11日","丽江一日游");

    }

    @Test
    public void test3(){
        JFrame frame = new JFrame("Button Click Example");
        JButton button = new JButton("Click Me!");

        // 使用 ActionListener 监听按钮的点击事件
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("Button clicked!");
            }
        });

        frame.add(button);
        frame.setSize(300, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

